package com.softer.chengxin.modify.dao;

import com.softer.chengxin.modify.entity.CompanyModify;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * @author Gong Zhiyang
 * @date 2019/9/10
 */
@Mapper
@Repository
public interface CompanyModifyDao {
    /**
     * 插入变更表
     *
     * @param companyModify 变更实体
     * @return 操作结果
     */
    @Insert("INSERT INTO company_modify(type,business_id,gmt_create,gmt_modify,state) VALUES(#{c.type},#{c.businessId},now(),now(),#{c.state})")
    @Options(useGeneratedKeys = true, keyProperty = "c.id", keyColumn = "id")
    int insert(@Param("c") CompanyModify companyModify);

    /**
     * 查询当前业务是否存在待审核状态
     *
     * @param id 业务ID
     * @return 变更实体
     */
    @Select("select id,type,state from company_modify where business_id=#{id} and state=0")
    CompanyModify getInfo(@Param("id") int id);

    /**
     * 审核结束后，将变更状态改为变更结束
     *
     * @param id 业务ID
     * @return 变更结果
     */
    @Update("update company_modify set state=1 ,gmt_modify=now() where business_id=#{id} and state=0")
    int updateState(@Param("id") int id);
}
